from flask import Flask

from apps.pojo.Entity import db

from apps.controller.UserController import user
from apps.controller.IndexController import index
from apps.controller.LoginController import login_blue


app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:13456@{ipaddress}:{port}/{database}".format( ipaddress="localhost",port="3306",database="flask")
app.config["SQLALCHEMY_ECHO"]= True  # 打印sql语句
app.config["SECRET_KEY"] = 'dsjjkhkhjsdkjchkj' # session加密

app.register_blueprint(login_blue) #将蓝图注册到app中
app.register_blueprint(user) #将蓝图注册到app中
app.register_blueprint(index) #将蓝图注册到app中


# @app.before_request
# def before_request():
#     # 判断请求地址是/ 则不走下面的判断
#     if session.get("username") and request.endpoint not in ('login', 'static'):
#         return redirect("/login")


with app.app_context():
    db.init_app(app)
    # db.drop_all()
    # db.create_all()

if __name__ == '__main__':
    app.run()